//
//  AcgGridController.m
//  oc1
//
//  Created by kokuma on 2017/2/12.
//  Copyright © 2017年 kokumams. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "AcgGridController.h"
#import "AcgCell.h"
#import "AcgBean.h"

@interface AcgGridController ()

@end

@implementation AcgGridController

- (void)viewDidLoad {
    [super viewDidLoad];
}
//需要重载的方法
- (void)setupCells{
    [self.myCollectView registerClass:[AcgCell class] forCellWithReuseIdentifier:kCellIdentifier_AcgCell];
}

//需要重载的方法 
- (void)getDataList{
    printf("getDataList");
    MPNetAPIManager *netAPI = [MPNetAPIManager sharedManager];
    if(!self.dataList){
        self.dataList = [NSMutableArray new];
    }
    NSMutableArray *originData = self.dataList;
    [originData removeAllObjects] ;
    [netAPI getAcgsByKeyword:@"1" andBlock:^(id data, NSError *error) {
        if(data){
            NSMutableArray *allData = data;
            
            // [weakSelf.dataList removeAllObjects];
            for(id temp in allData){
                AcgBean *bean = [[AcgBean alloc] initWithDictionary:temp];
                // NSLog([@(bean.id.longValue) stringValue]);
                 NSLog(bean.name);
                [originData addObject:bean];
            }
            [self.myCollectView reloadData];
        }
    }];
}


//需要重载的方法
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    AcgCell *cell = [self.myCollectView dequeueReusableCellWithReuseIdentifier:kCellIdentifier_AcgCell forIndexPath:indexPath];
    // [cell layoutHeight];
    if(self.dataList){
        [cell configViewWithModel:self.dataList[indexPath.row]];
    }
    // __weak typeof(self) weakSelf = self;
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end